package com.cdie.myschool.service.impl;

import com.cdie.myschool.common.R;
import com.cdie.myschool.domain.dto.StudentAbilityDTO;
import com.cdie.myschool.domain.entity.Calendar;
import com.cdie.myschool.domain.entity.EnjoyRunningInfo;
import com.cdie.myschool.domain.vo.StudentAbilityVO;
import com.cdie.myschool.mapper.StudentAbilityMapper.StudentAbilityMapper;
import com.cdie.myschool.service.StudentAbilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 雷金臣199000347
 * @date 2022/10/12 - 20:42
 */
@Service
public class StudentAbilityServiceImpl implements StudentAbilityService {
    @Autowired
    private StudentAbilityMapper studentAbilityMapper;
    @Override
    public R<StudentAbilityVO> getStudentAbility(StudentAbilityDTO studentAbilityDTO) {
        StudentAbilityVO studentAbilityVO=new StudentAbilityVO();
        studentAbilityVO.setSName(studentAbilityMapper.getStudentName(studentAbilityDTO.getStudentCode()));
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long distance=0;
        List tList=new ArrayList();
        Calendar c=studentAbilityMapper.getCalendar2(studentAbilityDTO);
        String b=f.format(c.getBeginTime());
        String begin=b.replace("-","").replace(" ","").replace(":","");
        long beginTime=Long.valueOf(begin);
        String e=f.format(c.getEndTime());
        String end=e.replace("-","").replace(" ","").replace(":","");
        long endTime=Long.valueOf(end);
        int countOfScholarship=studentAbilityMapper.getScholarship(c.getSemesterId(),studentAbilityDTO.getStudentCode());
        if(countOfScholarship>=1){
            String xb="超级学霸";
            tList.add(xb);
        }
        int countOfPassLibrary=studentAbilityMapper.getLibraryPassRecord(c.getSemesterId(),studentAbilityDTO.getStudentCode());
        if(countOfPassLibrary>=5){
            String zl="自律达人";
            tList.add(zl);
        }
        List<EnjoyRunningInfo> list= studentAbilityMapper.getEnjoyRunningInfo(c.getSemesterId(),studentAbilityDTO.getStudentCode());
        for (int i = 0; i <list.size() ; i++) {
            String tsp=f.format(list.get(i).getTimeStamp());
            String ts=tsp.replace("-","").replace(" ","").replace(":","");
            long timeStamp=Long.valueOf(ts);
            if(timeStamp>=beginTime&&timeStamp<=endTime){
                distance= distance+list.get(i).getMovingDistance().longValue();
            }
        }
        if (distance>=10){
            StudentAbilityVO s=new StudentAbilityVO();
            String yd="运动达人";
            tList.add(yd);
        }
        return R.Success("能力标签如下",tList);
    }
}
